<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            margin: 0;
        }

        .header {
            height: 50px;
            line-height: 50px;
            background: rgba(47, 47, 47, 0.98);
        }

        section {
            width: 600px;
            padding: 0 10px;
            margin: 0 auto;

        }

        label {
            float: left;
            width: 100px;
            line-height: 50px;
            color: #DDD;
            font-size: 24px;
            cursor: pointer;
            font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        }

        .header input {
            float: right;
            width: 60%;
            height: 24px;
            margin-top: 12px;
            text-indent: 10px;
            border-radius: 5px;
            box-shadow: 0 1px 0 rgba(255, 255, 255, 0.24), 0 1px 6px rgba(0, 0, 0, 0.45) inset;
            border: none;
        }

        h2 {
            position: relative;
        }

        ol,
        ul {
            padding: 0;
            list-style: none;
        }

        li {
            height: 32px;
            line-height: 32px;
            background: #fff;
            position: relative;
            margin-bottom: 10px;
            padding: 0 45px;
            border-radius: 3px;
            border-left: 5px solid #629A9C;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
        }

        li input {
            position: absolute;
            top: 2px;
            left: 10px;
            width: 22px;
            height: 22px;
            cursor: pointer;
        }

        ul li {
            border-left: 5px solid #999;
            opacity: 0.5;
        }

        a,
        span {
            position: absolute;
            top: 2px;
            right: 5px;
            display: inline-block;
            padding: 0 5px;
            height: 20px;
            border-radius: 20px;
            background: #E6E6FA;
            line-height: 22px;
            text-align: center;
            color: #666;
            font-size: 14px;
        }
    </style>
</head>

<body>
    <div class="header">
        <section>
            <label for="">备忘录</label>
            <input type="text" id="title" name="title" placeholder="新增待办事项" required>
        </section>
    </div>
    <section>
        <h2>正在进行<span id="todocunt">0</span></h2>
        <ol id="todolist" class="demo-box">
            <li>
                <input type="checkbox" name="" id="">
                <p>123</p>
                <a href="#">删除</a>
            </li>
        </ol>
        <h2>已经完成<span id="donecount">0</span></h2>
        <ul id="donelist">
            <li>
                <input type="checkbox" name="" id="" checked>
                <p>456</p>
                <a href="#">删除</a>
            </li>
        </ul>
        <footer>
            Copyright © 2014 todolist.cn
        </footer>
    </section>
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <script>
        $(function () {
            load();
        });

        function load() {
            enter();
            check1();
            check2();
            count();
            del();
        }
        //键入
        function enter() {
            $(".header").off("keydown").keydown(function () {
                if (event.keyCode == "13") {
                    var text = $("#title").val();
                    console.log(text);
                    $("#title").val("");
                    var html = `
                <li>
                <input type="checkbox" name="" id="">
                <p>${text}</p>
                <a href="#">删除</a>
                </li>`;
                    $("#todolist").append(html);
                    load();
                }
            })

        }
        //勾选1
        function check1() {
            $("ol>li>input[type='checkbox']").on("click", function () {
                var obj = $(this).parent();
                obj.parent().parent().find("ul").prepend(obj);
                load();
            })
        }
        //勾选2
        function check2() {
            $("ul>li>input[type=checkbox]").on("click", function () {
                var obj = $(this).parent();
                obj.parent().parent().find("ol").append(obj);
                load();
            })
        }
        //计数
        function count() {
            $("#todocunt").text($("ol>li").length);
            $("#donecount").text($("ul>li").length);
        }
        //删除
        function del() {
            $("li>a").on("click", function () {
                $(this).parent().remove();
                load();
            })
        }
    </script>
</body>

</html>